import { Component, OnInit, ViewChild } from '@angular/core';
import { NavController, IonAccordionGroup } from '@ionic/angular';


@Component({
  selector: 'page-d01',
  templateUrl: './d01.page.html',
  styleUrls: ['./d01.page.scss'],
})
export class D01Page implements OnInit {

  constructor(public navCtrl: NavController) { }
  @ViewChild(IonAccordionGroup, { static: true }) accordionGroup: IonAccordionGroup;

  isKaifeng: boolean;

  ionViewDidLoad() {

  }

  //显示基本的开封地图(Hello World)
  click1() {
    this.accordionGroup.value = undefined;
    this.isKaifeng = true;

    //创建百度地图API的MAP实例
    let map = new BMap.Map('bdmap');

    //设置地图中心点坐标（河大计算机学院门前路上）
    let point = new BMap.Point(114.315, 34.821);
    //初始化地图和地图级别
    map.centerAndZoom(point, 15)
    //开启鼠标滚轮缩放【默认不开启】
    map.enableScrollWheelZoom();
  }

  //切换城市并显示带控件控制的北京或开封地图
  click2() {
    this.accordionGroup.value = undefined;
    this.isKaifeng = !this.isKaifeng;
    let map = new BMap.Map("bdmap");
    if (this.isKaifeng) {
      map.centerAndZoom(new BMap.Point(114.315745, 34.824635), 11);
      map.setCurrentCity("开封")
    } else {
      //初始化地图，设置中心坐标和地图级别
      map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
      map.setCurrentCity("北京")
    }
    //添加平移缩放控件
    map.addControl(new BMap.NavigationControl());
    //添加比例尺控件
    map.addControl(new BMap.ScaleControl());
    //添加缩略图控件
    map.addControl(new BMap.OverviewMapControl());

    //添加默认的地图类型控件
    map.addControl(new BMap.MapTypeControl());
    //开启鼠标滚轮缩放
    map.enableScrollWheelZoom();
  }

  ngOnInit() {
    this.isKaifeng = true;
  }

}
